<?php
$idFuncionario = $_REQUEST['idFuncionario'];
$funcionario = $em->find("Entities\Funcionario", $idFuncionario);

$aquisicoes = $funcionario->getAquisicoes();

$xml="";

foreach ($aquisicoes as $aquisicao) {
	if($aquisicao->getMotivoDevolucao() == "EXCLUIR"){
		continue;
	}
	$xml.="<aquisicao>";
	$xml.=	"<idAquisicao>".$aquisicao->getId()."</idAquisicao>";
	$xml.=	"<descricaoMaterial>".$aquisicao->getDescricaoMaterial()."</descricaoMaterial>";
	$xml.=	"<qtd>".$aquisicao->getQtd()."</qtd>";
	$xml.=	"<dataAquisicao>".date('d/m/Y', $aquisicao->getDataAquisicao()->getTimestamp())."</dataAquisicao>";
	$dataDevolucao = $aquisicao->getDataDevolucao();
	$dataDevolucao = empty($dataDevolucao)? '': date('d/m/Y', $aquisicao->getDataAquisicao()->getTimestamp());
	$xml.=	"<dataDevolucao>".$dataDevolucao."</dataDevolucao>";
	$diasVal = $aquisicao->getEstoque()->getMaterial()->getTempoValidade()*60*60*24;
	$timestampValPrev = $diasVal + $aquisicao->getDataAquisicao()->getTimestamp();
	$timestampHoje = strtotime(date("m/d/Y"));
	$vencido = "false";
	if($timestampHoje > $timestampValPrev){
		$vencido = "true";
	}
	$xml.=	"<dataDevolucaoPrevista>".date('d/m/Y', $timestampValPrev)."</dataDevolucaoPrevista>";
	$xml.=	"<vencido>".$vencido."</vencido>";
	$xml.="</aquisicao>";
}

echo $xml;